from fbprophet import Prophet
import pandas as pd
import logging
import warnings
from fbprophet.plot import plot_yearly
logging.getLogger('fbprophet').setLevel(logging.ERROR)
warnings.filterwarnings("ignore")
df1 = pd.read_csv('./data/sale_all_years.csv')


df = df1.iloc[0, :].T.iloc[3:, ].reset_index()
df = df.rename(columns={'index': 'ds', 0: 'y'})
df['ds'] = df['ds'].apply(lambda x: x[:4]+'-'+x[4:]+'-'+'01')

m = Prophet()
m.add_seasonality(name='monthly', period=30.5, fourier_order=5)
# m.add_country_holidays(country_name='CN')
m.fit(df)
future = m.make_future_dataframe(4, freq='MS')
forecast = m.predict(future)

y = forecast['yhat']
import matplotlib.pyplot as plt
plt.plot(range(len(future)), y)
plt.plot(range(len(df['ds'])), df['y'])
plt.ylim([400, 900])
plt.show()